﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ART.Common;

namespace ART.Admini.Setting
{
    public partial class SchoolZYDetail : System.Web.UI.Page
    {
        protected int Id = 0;
        private ART.BLL.B_SchoolZY bll = new ART.BLL.B_SchoolZY();
        private ART.Model.M_SchoolZY model = new ART.Model.M_SchoolZY();
        protected string parentLdg = "schoolAdd";

        protected void Page_Load(object sender, EventArgs e)
        {
            Id = Common.LYRequest.GetInt("id", 0);
#warning BLL.B_TBAdmin.IsPermissions(0x6c)
            if (Id > 0)
            {
                parentLdg = "schoolEdit";
            }
            if (!IsPostBack)
            {
                InitData();
            }
        }
        private void InitData()
        {
            txtSchoolName.Attributes.Add("onclick", "javascript:openDlg('SchoolDialog','查找学校','../Controls/_SchoolDialog.aspx?hidCtl=ctl00_cphContent_hidSchoolId&txtCtl=ctl00_cphContent_txtSchoolName','500px','auto','" + parentLdg + "');");

            JBind.BindList(dropParentId, JTree.GetClassTree(2, bll.GetList("").Tables[0], "ParentID", "0", "SubobjectName"));
            dropParentId.Items.Insert(0, new ListItem("一级分类", "0"));

            if (Id > 0)
            {//edit
                model = bll.GetModel(Id);
                if (model != null)
                {
                    hidSchoolId.Value = model.SchoolId.ToString();
                    txtSchoolName.Text = new BLL.B_SchoolDic().GetModel(model.SchoolId).SchoolName;

                    txtSubobjectName.Text = model.SubobjectName;
                    dropParentId.SelectedValue = model.ParentId.ToString();
                    txtSort.Text = model.Sort.ToString();
                }
            }
        }
        protected void btnSave_Click(object sender, EventArgs p1)
        {
            if (Id > 0)
            {
                #region __________Edit__________
                model = bll.GetModel(Id);
                model.SchoolId = int.Parse(hidSchoolId.Value);
                model.SubobjectName = txtSubobjectName.Text;
                model.ParentId = int.Parse(dropParentId.SelectedValue);
                model.Sort = int.Parse(txtSort.Text);
                if (bll.Update(model))
                {
                    //B_operationLog.CreateOperationLog(B_operationLog.operationLogType.Edit, "", "");
                    MessageBox.JSLoad(sender, "alert('保存成功!');reloadDlg(true);");
                }
                #endregion
            }
            else
            {
                #region __________Add__________
                model.Id = bll.GetMaxId();
                model.SchoolId = int.Parse(hidSchoolId.Value);
                model.SubobjectName = txtSubobjectName.Text;
                model.ParentId = int.Parse(dropParentId.SelectedValue);
                model.Sort = int.Parse(txtSort.Text);
                if (bll.Add(model) > 0)
                {
                    //B_operationLog.CreateOperationLog(B_operationLog.operationLogType.Add, "", "");
                    MessageBox.JSLoad(sender, "alert('保存成功!');reloadDlg(true);");
                }
                #endregion
            }
        }
    }
}
